package com.mengdie.shuidi.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.utils.EmptyUtils;
import com.mengdie.shuidi.R;
import com.mengdie.shuidi.manager.MDModel;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：HQY on 2018/11/26 10:56
 * 邮箱：hqy_xz@126.com
 */

public class SoftwareSettingActivity extends BaseActivity {

    @Bind(R.id.iv_set_open)
    ImageView mIvSetOpen;
    @Bind(R.id.iv_set_close)
    ImageView mIvSetClose;
    @Bind(R.id.tv_generic_title)
    TextView mTvGenericTitle;

    private String mIdnex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_software_setting);
        ButterKnife.bind(this);
        mTvGenericTitle.setText("软件设置");
        setSelect(EmptyUtils.isEmpty(MDModel.getInstance().getIsOpen()) ? "2" : MDModel.getInstance().getIsOpen());
    }

    @OnClick({R.id.rl_generic_back, R.id.rl_set_open, R.id.rl_set_close, R.id.tv_set_save})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_generic_back:
                finish();
                break;
            case R.id.rl_set_open:
                mIdnex = "1";
                setSelect(mIdnex);
                break;
            case R.id.rl_set_close:
                mIdnex = "2";
                setSelect(mIdnex);
                break;
            case R.id.tv_set_save:
                MDModel.getInstance().setIsOpen(mIdnex);
                MDModel.getInstance().writeToCache();
                finish();
                break;
            default:
                break;
        }
    }

    private void setSelect(String idnex) {
        mIvSetOpen.setVisibility(idnex.equals("1") ? View.VISIBLE : View.GONE);
        mIvSetClose.setVisibility(idnex.equals("2") ? View.VISIBLE : View.GONE);
    }

}
